#!/bin/bash

status=`cat /var/run/wview/wview.sts | awk '/status =/ {print $NF}'`

if [ $status -eq "3" ]; then exit 0; fi

array=("Not Started" "Booting" "Wait for wviewd" "Running" "Shutdown" "Error")
message=`cat /var/run/wview/wview.sts | awk '/message =/'`

echo "On "`date`", wview process was in state ${array[$status - 1]} with $message" >> /home/pi/logs/wview_log

if [ $status -ne "5" ]; then exit 0; fi

initfail=`echo $message | grep stationInit`

if [ -z "$initfail" ]; then exit 0; fi

/home/pi/siweather/scripts/set_console_term

sudo service wview restart

exit 0
